#include<iostream>
#include<unistd.h>
#include<sys/types.h>
#include<signal.h>
using namespace std;
void PrintPending(sigset_t& pending)
{
    for (int i = 31; i > 0;i--)
    {
        if(sigismember(&pending,i))
        {
            cout << "1";
        }
        else
        cout << "0";
    }

    cout << endl;
}
void hander(int sig)
{
    cout << "unblock" << endl;
    sigset_t pending;
    sigpending(&pending);
    PrintPending(pending);
}
int main()
{
    signal(2, hander);
    // 屏蔽2号信号
    sigset_t old_set, block_set;
    sigemptyset(&old_set);
    sigemptyset(&block_set);
    sigaddset(&block_set, 2);//此处并没有修改pcb的block表
    //修改pcb的block表
    sigprocmask(SIG_BLOCK, &block_set, &old_set);
    int cnt = 10;
    while (1)
    {
        if(cnt==0)//解除屏蔽
            sigprocmask(SIG_SETMASK, &old_set, &block_set);
        sigset_t pending;
        sigpending(&pending);
        PrintPending(pending);
        sleep(1);
        cnt--;
    }
    return 0;
}